package org.dllwh.utils;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import cn.hutool.setting.dialect.Props;
import cn.hutool.setting.dialect.PropsUtil;
import com.google.common.collect.Maps;
import okhttp3.*;
import org.dllwh.utils.google.OkHttpHelper;
import org.junit.Test;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * <p>
 * Today the best performance as tomorrow the newest starter!
 *
 * @ClassName OkHttpTest
 * @Description OkHttp 测试
 * @Date 2025-06-03 15:54
 * @版本 V 1.0.1
 * @since JDK 17
 */
public class OkHttpTest {
    static String url = "https://my.ip.cn/json/";
    static String postUrl = "https://apis.juhe.cn/ip/Example/query.php?IP=122.193.105.215";
    // static String postUrl = "https://apis.juhe.cn/ip/Example/query.php";

    public static void main(String[] args) throws IOException {
    }

    /**
     * POST提交字符串
     */
    @Test
    public void test01() throws IOException {
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        OkHttpClient client = new OkHttpClient();
        RequestBody requestBody = RequestBody.create("", mediaType);
        Request request = new Request.Builder().url("https://app.ipdatacloud.com/v1/ip_self_search").post(requestBody).build();
        try (Response response = client.newCall(request).execute()) {
            if (response.body() != null) {
                System.out.println(response.body().string());
            }
        }
    }

    /**
     * POST提交表单
     */
    @Test
    public void test02() throws IOException {
        OkHttpClient client = new OkHttpClient();
        RequestBody formBody = new FormBody.Builder()
                .add("search", "Jurassic Park")
                .build();
        Request request = new Request.Builder()
                .url("https://en.wikipedia.org/w/index.php")
                .post(formBody)
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (response.body() != null) {
                System.out.println(response.body().string());
            }
        }
    }

    @Test
    public void test03() throws IOException {
        Request request = new Request.Builder()
                .url("")
                .addHeader("Content-Type", "application/json")
                .header("Accept", "application/json")
                .build();
    }
}
